# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>

pkgbase=liquid-dsp
pkgname=($pkgbase $pkgbase-sse4.1)
pkgver=1.6.0
pkgrel=1
pkgdesc='Open-source signal processing library for software-defined radios'
arch=('loong64' 'x86_64')
url='https://liquidsdr.org'
license=('MIT')
depends=('glibc')
optdepends=('fftw: efficient FFT')
source=("https://github.com/jgaeddert/liquid-dsp/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('2567d03515e87ab0c047158aeaabb560be711ac54d0b8294b19782104089c4cc61e5b1ec6d3e9ab78162224d4a2d4623e3694e497572d573cb4ce6f451d0a078')

prepare() {
    mkdir $pkgbase-sse4.1-$pkgver
    cp -r $pkgbase-$pkgver/* $pkgbase-sse4.1-$pkgver

    sed -i 's|ax_cv_have_sse41_ext=.*|ax_cv_have_sse41_ext=yes|' $pkgbase-sse4.1-$pkgver/scripts/ax_ext.m4
}

build() {
    echo 'Building liquid-dsp...'
    cd "$srcdir"/$pkgbase-$pkgver

    autoreconf -vif
    enable_simdoverride='' ./configure --prefix=/usr

    make

    echo 'Building liquid-dsp-sse4.1...'
    cd "$srcdir"/$pkgbase-sse4.1-$pkgver

    autoreconf -vif
    ./configure --prefix=/usr

    make
}

check() {
    echo 'Checking liquid-dsp...'
    cd "$srcdir"/$pkgbase-$pkgver

    make check

    echo 'Checking liquid-dsp-sse4.1...'
    cd "$srcdir"/$pkgbase-sse4.1-$pkgver

    make check
}

package_liquid-dsp() {
    cd $pkgbase-$pkgver

    make DESTDIR="$pkgdir" install

    install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_liquid-dsp-sse4.1() {
    pkgdesc="$pkgdesc (with SSE 4.1 extensions)"
    provides=('liquid-dsp')
    conflicts=('liquid-dsp')

    cd $pkgbase-sse4.1-$pkgver

    make DESTDIR="$pkgdir" install

    install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

